// pages/detail/detail.js
var util = require('../../utils/util.js');
Page({
   onShareAppMessage: function () {
    return {
      title: this.data.title,
      path: '/pages/detail/detail?id='+this.data.id
    }
  },
  goSetPhone:function(event){

    try {
      var token = wx.getStorageSync('tonken');
    } catch (e) {
      // Do something when catch error
    }

    if(token.length>0){
      wx.switchTab({
        url: '/pages/mysetting/mysetting'
      })
    }else{
      wx.navigateTo({
        url: '../setphone/setphone',
        success: function(res){
          // success
        },
        fail: function() {
          // fail
        },
        complete: function() {
          // complete
        }
      })
    }

  },
  data:{
    mplink:"#",
    title:"",
    detail:"",
    id:"1",
    txtCome:"预约到店",
    txtComeCls:"",
    plain:"true"
  },
  calling:function(){
    wx.makePhoneCall({
      phoneNumber: util.customerService, //此号码并非真实电话号码，仅用于测试
      success:function(){
        console.log("拨打电话成功！")
      },
      fail:function(){
        console.log("拨打电话失败！")
      }
    })
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    
    this.setData({
      id:options.id
    });
  
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    var that = this;
    // 页面显示
    wx.showToast({
          title: '',
          icon: 'loading',
          })
    wx.request({
      url: util.url(),
      data: util.reformParam(util.podcastDetails,{"id":this.data.id}),
      method: 'POST',
      success: function(res){
        if(res.data && res.data.success){
          that.setData({
            mplink:res.data.single.link+"?"+util.version,
            title:res.data.single.theme,
            detail:res.data.single.remark.replace(/&&/g,'。'),
          });
          wx.setNavigationBarTitle({
            title: res.data.single.theme
          });
          wx.hideToast();
        }else{
          wx.hideToast();
          wx.showToast({
            title: '请求失败',
            icon: 'success',
            duration: 2000
          })
        }
      },
      fail: function() {
        wx.hideToast();
        wx.showToast({
          title: '网络请求失败',
          icon: 'success',
          duration: 2000
          })
      },
      complete: function() {
        // complete
      }
    })
    
    try {
      var token = wx.getStorageSync('tonken');
    } catch (e) {
      // Do something when catch error
    }

    if(token.length>0){
      this.setData({
        txtCome:"已预约",
        txtComeCls:"txtComeCls",
        plain:""
      });
    }else{
      this.setData({
        txtCome:"预约到店",
        txtComeCls:"",
        plain:"true"
      });
    }




  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})